/*
 * @FileName: [FileUploadUtil.java]
 * 
 * @Package com.bcinfo.upp.admin.util
 * 
 * 
 * Copyright (c) 2011-2015 BCINFO Technology Limited Com. All rights reserved.
 * 
 * This software is the confidential and proprietary information of BCINFO
 * Technology Limited Company ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in accordance
 * with the terms of the contract agreement you entered into with RKY.
 * 
 * $Rev: 44 $ $LastChangedDate: 2013-10-12 10:19:57 +0800 (星期六, 12 十月 2013) $
 * $LastChangedBy: wanggc $
 * 
 * @category bcinfo-upp
 * 
 * @version 1.1
 * 
 * @author $Author: wanggc $
 * 
 * Change History:[Formatter: author date description] <br/> 1 2 3
 */

package com.bcinfo.iccard.admin.util;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

/**
 * 文件路径工具类<br/>
 * <p>
 * Description:<br/>
 * <p>
 * 处理文件路径
 * 
 * <p>
 * For Examples <br/>
 * 
 * <PRE>
 * FilePathUtil.getPhysicalPath(request, path);
 * </PRE>
 * <p>
 */
public class FilePathUtil
{

    private FilePathUtil()
    {

    }

    /**
     * 对路径加载上根目录路径<br/>
     * <p>
     * <p>
     * Author: yun<br/>
     * <p>
     * Date: 2013-5-15-下午5:25:31<br/>
     * <p>
     * 
     * @param request
     * @param path
     * @return
     * 
     */
    public static String addRootUrlPath(String rootpath, String path)
    {
        return rootpath + path;
    }

    /**
     * 对路径加载上根目录路径<br/>
     * <p>
     * <p>
     * Author: yun<br/>
     * <p>
     * Date: 2013-5-15-下午5:25:31<br/>
     * <p>
     * 
     * @param request
     * @param path
     * @return
     * 
     */
    public static String removeRootUrlPath(String rootpath, String path)
    {
        int begin = path.indexOf(rootpath) + rootpath.length();
        return path.substring(begin);
    }

    /**
     * 获取传入路径的物理路径 <br/>
     * <p>
     * Description: 根据相对路径转换成相对于项目的物理路径 <br/>
     * <p>
     * Author: yun<br/>
     * <p>
     * Date: 2013-5-15-下午5:25:31<br/>
     * <p>
     * 
     * @param request
     * @param path
     * @return
     * 
     */
    public static String getPhysicalPath(HttpServletRequest request, String path)
    {
        String realPath = request.getSession().getServletContext().getRealPath("/");
        File file = new File(realPath + File.separator + path);

        if (!file.exists())
        {
            file.mkdirs();
        }

        return file.getPath();
    }

}
